package com.cn.controller.backstage;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cn.controller.BaseServlet;
import com.cn.entity.Activity_entity;
import com.cn.service.backstage_huodong_contlr;

@WebServlet("/backstage_huodong")
public class backstage_huodong extends BaseServlet{
	private backstage_huodong_contlr activity;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		activity = new backstage_huodong_contlr();
		List<Activity_entity> list = activity.getmember();
		req.setAttribute("list", list);
		forward("backstage_huodong");
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		activity = new backstage_huodong_contlr();
		String id = req.getParameter("xg_id");
		if (id != "" && id != null) {
			int xg_id = Integer.parseInt(req.getParameter("xg_id").toString());
			String xg_title = req.getParameter("xg_title");
			String xg_url = req.getParameter("xg_url");
			String xg_content = req.getParameter("xg_content");
			String xg_activity_type = req.getParameter("xg_radio");
			int type=Integer.parseInt(xg_activity_type);
			String xg_activity_time = req.getParameter("xg_time");
			int xg_row=activity.upactivity(xg_id, xg_title, xg_url, xg_content, type, xg_activity_time);
			if (xg_row != -1) {
				System.out.println("修改成功");
			} else {
				System.out.println("修改失败");
			}
		}
		String title = req.getParameter("add_title");
		if (title != "" && title != null) {
			String add_title = req.getParameter("add_title");
			String add_url = req.getParameter("add_url");
			String add_content = req.getParameter("add_content");
			String add_activity_type = req.getParameter("add_radio");
			int type=Integer.parseInt(add_activity_type);
			String add_activity_time = req.getParameter("add_time");
			int xg_row=activity.addactivity(add_title, add_url, add_content, type, add_activity_time);
			if (xg_row != -1) {
				System.out.println("添加成功");
			} else {
				System.out.println("添加失败");
			}
		}
		
		List<Activity_entity> list = activity.getmember();
		req.setAttribute("list", list);
		forward("backstage_huodong");
	}
}
